package com.wan.zuochengyun_v2.stack_queue;

import java.util.LinkedList;

/**
 * 坑点：Integer相等使用equals
 */
public class A1_MinStack {
    private LinkedList<Integer> stackData = new LinkedList();
    private LinkedList<Integer> stackMin = new LinkedList();

    public void push(int val) {
        stackData.push(val);
        if (stackMin.peek() == null || stackMin.peek() >= val) {
            stackMin.push(val);
        }
    }

    public void pop() {
        Integer var = stackData.peek();
        stackData.pop();
        if (var.equals(stackMin.peek())) {
            stackMin.pop();
        }
    }

    public int top() {
        return stackData.peek();
    }

    public int getMin() {
        return stackMin.peek();
    }

    public static void main(String[] args) {
        A1_MinStack stack = new A1_MinStack();
        stack.push(512);
        stack.push(-1024);
        stack.push(-1024);
        stack.push(512);
        stack.pop();
        System.out.println(stack.getMin());
        stack.pop();
        System.out.println(stack.getMin());
        stack.pop();
        System.out.println(stack.getMin());


    }
}

